var vm = new Vue({
    el: '#app',
    data: {
        host: host,
        spit: [],
        spit_id: '',
        spit_url: '',
        spit_comments: [],
    },


    mounted: function () {
        // 判断用户的登录状态
        // if (this.user_id && this.token) {
        //     axios.get(this.host + '/user/', {
        //         // 向后端传递JWT token的方法
        //         headers: {
        //             'Authorization': 'JWT ' + this.token
        //         },
        //         responseType: 'json',
        //     })
        //         .then(response => {
        //             // 加载用户数据
        //             this.user_id = response.data.id;
        //             this.username = response.data.username;
        //             this.avatar = response.data.avatar;
        //             if (!this.avatar) {
        //                 this.avatar = './img/widget-photo.png'
        //             }
        //         })
        //         .catch(error => {
        //             if (error.response.status == 401 || error.response.status == 403) {
        //                 var arrUrl = document.location.toString().split('/');
        //                 location.href = '/person-loginsign.html?next=/' + arrUrl;
        //             }
        //         });
        // } else {
        //     this.user_id = null;
        //     this.username = null;
        //     this.token = null
        // }
        // 获取头条详情
        var id = this.get_query_string();
        axios.get(this.host + '/spits/' + id, {
            responseType: 'json',
            withCredentials: true,
        }).then(response => {
            this.spit = response.data;
        }).catch(error => {
            console.log(error.response.data);
        });
        // 获取评论
        axios.get(this.host + '/spits_comments/' + id, {
            responseType: 'json',
            withCredentials: true,
        }).then(response => {
            this.spit_comments = response.data;
        }).catch(error => {
            console.log(error.response.data);
        });
    },


    methods: {
        // 获取url路径参数
        get_query_string: function () {
            var url = document.location.toString();
            var arrUrl = url.split('?id=');
            return arrUrl[1]
        },

    }

})
